package com.jetty;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.webapp.WebAppContext;

public class JettyDemo2 {

	public static void main(String[] args) {
QueuedThreadPool threadPool = new QueuedThreadPool(10, 1);
		
		//// 创建jetty web容器
		Server server = new Server(threadPool);
		// 在退出程序是关闭服务
		server.setStopAtShutdown(true);
        // 创建连接器，每个连接器都是由IP地址和端口号组成，连接到连接器的连接将会被jetty处理
		ServerConnector connector = new ServerConnector(server);
		connector.setHost("127.0.0.1");
		connector.setPort(1500);
		connector.setName("connenctor001");
		server.addConnector(connector);
		
		// 配置服务
		WebAppContext context = new WebAppContext();
		context.setContextPath("/jetty");
		context.setConfigurationDiscovered(true);
		context.setClassLoader(Thread.currentThread().getContextClassLoader());
		
		server.setHandler(context );
		try {
			server.start();
			server.join();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
